import sockettool from "../../common/js/sockettool.js"
import httptool from "../../common/js/httptool.js"
export default {
    data: {
        // 标记滑块是否显示
        gg:10,
        flag:0,
        httpsrc:null
    },
    props: {
        hmweight: {
            type:Number,
            default: 200,
        },
        cm:{
            type:Number,
            default:0
        }
    },
    onInit(){
        this.httpsrc=this.$app.$def.datas.serverurl;
    },
    setvalue(e){
        console.log("e.value ："+e.value+" "+this.gg);
        this.gg = e.value;
    },
    handgo(){

        this.hmweight=this.hmweight+this.gg;
        console.log(this.hmweight);
//        this.sethmweight(this.hmweight);
        this.$emit('sethmweight',this.hmweight);
//        this.$emit('sethmweight',{data:this.hmweight});

       // helloAsync(this.$app.$def.datas.tcp,this.gg);
        sockettool.socketSend(this.$app.$def.datas.tcp,this.gg)

    },
    openauto(){
        if(this.flag==0)
        {
            this.flag = 1;
            setTimeout(this.rendsever, 2000);
        }else{
            this.flag = 0;
        }
    },
    rendsever(){
        if(this.flag == 1){
            httptool.http_post_callback(this.$app.$def.datas.serverurl+"/tateTag_get",{name: "test"},this.refresh)
            setTimeout(this.rendsever, 2000);
        }else if(this.flag == 2){
            httptool.http_post_callback(this.$app.$def.datas.serverurl+"/tateTag_get",{name: "test"},this.refresh2)
            setTimeout(this.rendsever, 20000);
        }
    },
    refresh(data)
    {
        if(data[0].cv2state == 1)
        {
            this.$emit('setautoweight',10);
            sockettool.socketSend(this.$app.$def.datas.tcp,10)
            this.flag = 2;
        }
    },
    refresh2(data)
    {
        this.flag = 1;
        console.log("okok");
    }

}
//async function helloAsync(tcp,ff){
//    var cc=new Uint8Array([170,2,(30-ff)/2]);
//    tcp.send({
//        data:cc.buffer
//    },err => {
//        if (err) {
//            console.log('send fail');
//            return;
//        }
//        console.log('send success');
//    });
//}